home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 34 < prev    next >
Encoding:
Text File  |  1996-08-05  |  5.2 KB  |  155 lines

  1. Path: newsserv.grfn.org!jlendman
  2. From: jlendman@grfn.org (Jeret Lendman)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Listview Problem
  5. Date: 1 Jan 1996 12:07:52 GMT
  6. Organization: Grand Rapids Free-Net
  7. Message-ID: <4c8iqo$h16@newsserv.grfn.org>
  8. NNTP-Posting-Host: freenet.grfn.org
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Ok, I want to thank all those who are helping.  This post is to show all 
  12. the changes that have been made.  Richard Katzman was correct that the 
  13. minlist was the wrong type to allocate for.  And it has been changed.  
  14. here is my code again with changes.
  15.  
  16. I have made many comments in the code to show where the help is being 
  17. done.  Again, I feel it necessary to say thanx. 
  18.  
  19. struct TextAttr Topaz80 = {(STRPTR)"topaz.font",8,0,0};
  20.  
  21. /*******
  22.     makelabels is called from the main function, and is the first thing.
  23.     Then I open libraries, screen, and window.  And just before opening
  24.     the window, I call makegadgets.  I mention this because, someone
  25.     mentioned GT_RefreshWindow/Gadgets.  I create the gadget list and
  26.     attach the list before opening the window.  Refreshing should not be
  27.     neccessary.  But I could be wrong.
  28. *******/
  29.  
  30. void makegadgets(void)
  31. {
  32.   struct Gadget *qgadget;
  33.   int *vi=NULL;
  34.  
  35.   vi = GetVisualInfo(xscreen, TAG_END);
  36.   if(!vi)
  37.     printf("Error: Get Visual Info!\n");
  38.  
  39.   qgadget = (struct Gadget *)CreateContext(&gadgetlist);
  40.  
  41.   newgadget = (struct NewGadget *)AllocVec(sizeof(struct NewGadget), 
  42. MEMF_CLEAR);
  43.   newgadget->ng_LeftEdge   = 4;
  44.   newgadget->ng_TopEdge    = 20;
  45.   newgadget->ng_Width      = 250;
  46.   newgadget->ng_Height     = 160;
  47.   newgadget->ng_GadgetText = NULL;
  48.   newgadget->ng_TextAttr   = &Topaz80;
  49.   newgadget->ng_GadgetID   = 1;
  50.   newgadget->ng_Flags      = 0;
  51.   newgadget->ng_VisualInfo = vi;
  52.  
  53.   qgadget = CreateGadget(LISTVIEW_KIND, qgadget, newgadget, GTLV_Labels, 
  54. namelist, TAG_END);
  55. }
  56.  
  57.   makegadgets();
  58.   xwindow = (struct Window *)OpenWindowTags(NULL, WA_Left, 0,
  59.                                                   WA_Top,  0,
  60.                                                   WA_Width, 640,
  61.                                                   WA_Height, 200,
  62.                                                   WA_DetailPen, 2,
  63.                                                   WA_BlockPen, 0,
  64.                                   WA_IDCMP, (LISTVIEWIDCMP) | IDCMP_RAWKEY,
  65.                                                   WA_Gadgets, gadgetlist,
  66.                                                   WA_Title, windowtitle,
  67.                                                   WA_CustomScreen, xscreen,
  68.                                   WA_Flags, WFLG_SMART_REFRESH | WFLG_ACTIVATE);
  69.  
  70. void makelabels(void)
  71. {
  72.   size_t q;
  73.   char x;
  74.  
  75.   xtype = 0;
  76.   xfp = (FILE *)fopen("Xenolink:users/Userfile.xlk","rb+");
  77.   fseek(xfp, sizeof(struct User), SEEK_SET);
  78.  
  79.   namelist = (struct List *)AllocVec(sizeof(struct List), MEMF_CLEAR );
  80.   if(!namelist)
  81.   {
  82.     printf("Error: Allocating Memory for List!\n");
  83.     exit(0);
  84.   }
  85.   else
  86.   {
  87.     namelist->lh_Type=0; <- I have not read anywere that suggests what
  88.                             value goes here.  The book I have called
  89.                             "Mapping the Amiga" lists the different types
  90.                             of lists, but nothing for a general user list.
  91.                             I have reset this back to 0 for an unknown type.
  92.                             or should it be a 1.
  93.  
  94.     NewList((struct List *)namelist);
  95.   }
  96.  
  97.   do
  98.   {
  99.     q = fread(&xuser, sizeof(struct User), 1L, xfp);
  100.     if(q)
  101.     {
  102.       char *name;
  103.  
  104.       name = (char *)AllocVec(sizeof(xuser.Name), MEMF_CLEAR);
  105.       if(!name)
  106.         printf("Error: Allocating Memory for name!\n");
  107.       namenode = (struct Node *)AllocVec(sizeof(struct Node), MEMF_CLEAR);
  108.       if(!namenode)
  109.         printf("Error: Allocating Memory for namenode!\n");
  110.       namenode->ln_Name = name;
  111.  
  112.       for(x=0; xuser.Name[x]; x++)
  113.         name[x] = xuser.Name[x];
  114.  
  115. /****   ^^^^^^^^^^^^^^^^^^^^^^
  116.       I am still using this method to copy because when I AllocVec space
  117.       for the name all bytes are MEMF_CLEAR(ed).  When the _for_ statment
  118.       finishes, there are plenty of NULLs to terminate the string.
  119.       The sizeof xuser.Name is 25 bytes for those who were wondering.
  120. ****/  <-  I use the comment marks out of habit.
  121.  
  122.  
  123.       namenode->ln_Type = 100; <- I have not read anything to tell me
  124.                                   what value is proper.  the value here
  125.                                   is from the RKM example.
  126.  
  127.       AddTail((struct List *)namelist, (struct Node *)namenode);
  128.     }
  129.   }while(q);
  130.  
  131.   if(xfp)
  132.     fclose((FILE *)xfp);
  133. }
  134.  
  135. *****************************************************************************
  136.  
  137. Does anyone have an example that could be posted that works.  I can not 
  138. find any on aminet that includes the source that has a listview.
  139.  
  140. ******************************************************************************
  141.  
  142.   Jeret Lendman                                  E-Mail Jlendman@grfn.org
  143.   Grand Rapids MI.
  144.  
  145.  
  146.                          Long live the Amiga
  147.                 Amiga 1200 with GVP's turbo series II
  148.                             50MHz/+8megs
  149.  
  150.                      Loving Every Minute Of It!
  151.  
  152. ******************************************************************************
  153.  
  154.  
  155.